<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>权限分配</title>
    <meta name="keywords" content="S.Hackles--后台管理系统">
    <meta name="description" content="S.Hackles--后台管理系统">

    <link rel="shortcut icon" href="/favicon.ico">
    <link href="/Public/Admin/css/bootstrap.min14ed.css" rel="stylesheet">
    <link href="/Public/Admin/css/font-awesome.min93e3.css" rel="stylesheet">
    <link href="/Public/Admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <!-- Gritter -->
    <link href="/Public/Admin/js/plugins/gritter/jquery.gritter.css" rel="stylesheet">
    <!-- Morris -->
    <link href="/Public/Admin/css/plugins/morris/morris-0.4.3.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/animate.min.css" rel="stylesheet">
    <link href="/Public/Admin/css/style.min862f.css" rel="stylesheet">
    <link href="/Public/Admin/css/plugins/switchery/switchery.css" rel="stylesheet">
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <form action="<?php echo U('Admin/Group/rule');?>" method="post" id="forma">
        <input type="hidden" name="id" value="<?php echo ($id); ?>">
        <div class="col-sm-13">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-2">
                            <a href="<?php echo U('Admin/Group/index');?>" class="btn btn-outline btn-primary">返回分组列表</a>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>

                    <?php if(is_array($ruleInfo)): foreach($ruleInfo as $key=>$v1): ?><div class="row levelOne">
                        <label class="checkbox-inline"><input type="checkbox" name="ruleIds[]" value="<?php echo ($v1['id']); ?>" onclick="checkOne(this)" <?php if(in_array($v1['id'],$rules)): ?>checked<?php endif; ?> /><h4 style="margin-top: -3px"><?php echo ($v1['title']); ?></h4></label>
                        <div class="hr-line-dashed" style="margin-top: -4px;margin-bottom: 6px;"></div>

                        <?php if(!empty($v1['_child'])): if(is_array($v1['_child'])): foreach($v1['_child'] as $key=>$v2): $arrNum = count($v2['_child'])?><!--子元素数量-->
                                <div class="col-sm-<?php echo ($arrNum+2); ?> levelTwo" style="padding-left: 0px;font-size: 12px;">
                                <table class="table table-striped table-bordered table-hover table-condensed tmar">
                                    <tr class="b-group">
                                        <th width="23%"><label>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo ($v2['title']); ?> <input type="checkbox" name="ruleIds[]" value="<?php echo ($v2['id']); ?>" onclick="checkTwo(this)" <?php if(in_array($v2['id'],$rules)): ?>checked<?php endif; ?>></label></th>

                                        <?php if(!empty($v2['_child'])): ?><td class="levelThree">
                                            <?php if(is_array($v2['_child'])): foreach($v2['_child'] as $key=>$v3): ?><label>&nbsp;&nbsp;<?php echo ($v3['title']); ?>&nbsp;&nbsp;<input type="checkbox" name="ruleIds[]" value="<?php echo ($v3['id']); ?>" onclick="checkThree(this)" <?php if(in_array($v3['id'],$rules)): ?>checked<?php endif; ?> /></label><?php endforeach; endif; ?>
                                        </td><?php endif; ?>

                                    </tr>
                                </table>
                            </div><?php endforeach; endif; endif; ?>

                    </div><?php endforeach; endif; ?>

                    <input type="submit" id="submit" name="submit" value="提交" class="btnsub">
                </div>
            </div>
        </div>

    </form>
</div>
<script src="/Public/Admin/js/jquery.min.js"></script>
<script src="/Public/Admin/js/bootstrap.min.js"></script>
<script src="/Public/Admin/js/plugins/layer.3/layer.js"></script>
<script src="/Public/Admin/js/common.js"></script>
<script>
    $(function(){
        $('#submit').click(function () {
            var forma = new FormData (document.getElementById('forma'));
            $.ajax({
                url:$('#forma').prop('action'),
                type:'post',
                data:forma,
                dataType:'json',
                processData: false,
                contentType: false,
                success:function(data){
                    if(data.status > 0){
                        common.error(data.msg);
                    }else{
                        common.success(data.msg,"<?php echo U('Group/rule?id='.$id);?>");
                    }
                }
            });
            return false;
        });
    });
    function checkOne(obj){
        $(obj).parents('.levelOne').eq(0).find("input[type='checkbox']").prop('checked',$(obj).prop('checked'));
    }
    function checkTwo(obj){
        $(obj).parents('.levelTwo').eq(0).find("input[type='checkbox']").prop('checked',$(obj).prop('checked'));
    }
    function checkThree(obj){

    }
</script>
</body>
</html>